<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <title>登录-后台管理系统</title>
    <meta name="keywords" content="设置关键词..."/>
    <meta name="description" content="设置描述..."/>
    <meta name="author" content="DeathGhost"/>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge, chrome=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name='apple-touch-fullscreen' content='yes'>
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no">
    <meta name="format-detection" content="address=no">
    <link rel="icon" href="images/icon/favicon.ico" type="image/x-icon">
    <link rel="stylesheet" type="text/css" href="css/style.css"/>
    <script src="javascript/jquery.js"></script>
    <script src="javascript/public.js"></script>
    <script src="javascript/plug-ins/customScrollbar.min.js"></script>
    <script src="javascript/pages/login.js"></script>
    <script src="js/jquery.min.js"></script>
    <script src="layer/layer.js"></script>
    <script src="js/bootstrap.js"></script>
</head>
<body class="login-page">
<section class="login-contain">
    <header>
        <h1>后台管理系统</h1>
        <p>management system</p>
    </header>
    <div class="form-content">
        <ul>
            <li>
                <div class="form-group">
                    <label class="control-label">管理员账号：</label>
                    <input type="text" placeholder="管理员账号..." class="form-control form-underlined" id="adminName"/>
                </div>
            </li>
            <li>
                <div class="form-group">
                    <label class="control-label">管理员密码：</label>
                    <input type="password" placeholder="管理员密码..." class="form-control form-underlined" id="adminPwd"/>
                </div>
            </li>
            <li>
                <button class="btn btn-lg btn-block" id="login">立即登录</button>
            </li>
            <li>
                <p class="btm-info">©Copyright 2020</p>
                <address class="btm-info">无忧车险</address>
            </li>
        </ul>
    </div>
</section>
</body>
</html>

<script>
    $(function () {
        $("#login").click(function () {
        $.ajax({
            url: "http://localhost:9001/admin/login",
            data: {
                username: $("#adminName").val(),
                password: $("#adminPwd").val()
            },
            dataType: "JSON",
            type: "POST",
            success: function (data) {
                //登录的用户保存到会话储存
                sessionStorage.setItem("admin", JSON.stringify(data.data));
                // let user = sessionStorage.getItem("user");
                if (data.data.role === 1) {
                    window.location.href = "../survey/home.html";
                } else if (data.data.role === 2) {
                    window.location.href = "../myCenter/Audit.html";
                } else if (data.data.role === 3) {
                    window.location.href = "../pay/pay.html";
                } else {
                    window.location.href = "../report/home.html";
                }
            }, error: function () {
                layer.msg("failed");
            }
        })
    })   })
</script>
